﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace rInvoice
{
    public partial class CompanyAccount : UserControl
    {
        ServerObject mServerObject = null;
        string messageText = string.Empty;
        int mCompanyAccountID = 0;
        bool mSelectOneRow = false;

        public CompanyAccount(bool SelectOneRow, int companyAccount)
        {
            InitializeComponent();
            mServerObject = new ServerObject();
            mCompanyAccountID = companyAccount;
            mSelectOneRow = SelectOneRow;
        }

        private void CloseThisTab()
        {
            TabPage tabpage = (TabPage)this.Parent;
            TabControl tabControl = (TabControl)tabpage.Parent;
            tabControl.TabPages.Remove(tabpage);
        }

        private void FillGridView(bool selectOne, int account_id)
        {
            DataTable accListTable = new DataTable();

            if (selectOne)
            {
                DataRow accountRow = mServerObject.SelectCompanyAccountByID(account_id);
                accListTable.Rows.Add(accountRow);
            }
            else
            {
                accListTable = mServerObject.SelectCompanyAccountList(false);
            }
            dataGridView1.DataSource = accListTable;
        }

        private void closeButton_Click(object sender, EventArgs e)
        {
            CloseThisTab();
        }

        private void CompanyAccount_Load(object sender, EventArgs e)
        {
            FillGridView(mSelectOneRow, mCompanyAccountID);
        }

        private void selectButton_Click(object sender, EventArgs e)
        {
            bool selectOne = selectAllCheckBox.Checked;
            int CompanyID = 0;
            FillGridView(selectOne, CompanyID);
        }
    }
}
